package com.red.star.wechat.data.entity;

import com.red.star.wechat.data.utils.CheckUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Table;
import java.util.Date;

/**
 * @ProjectName: macalline-work-server
 * @Package: com.red.star.macalline.data.entity
 * @Description: 通话记录
 * @Author: AMGuo
 * @CreateDate: 2018/8/31 下午3:45
 * @Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "lg_voice")
public class LgVoice extends BaseEntity {

    /**
     * 真实主叫号码
     */
    private String calling;

    /**
     * 真实被叫号码
     */
    private String called;

    /**
     * 号码绑定关系
     */
    private Integer hostingVoiceId;

    /**
     * 通话时长。单位：秒
     */
    private String duration;

    /**
     * 呼叫结束原因。取值如下：
     * <p>
     * 1：Caller Hang up：主叫挂机
     * 2：Called Hang up：被叫挂机
     * 3：Not Reachable：被叫不可达
     * 4：Route Failure：路由被叫失败
     * 5：No Answer：被叫无应答
     * 6：Abandon：主叫放弃
     * 7：Call Terminated：呼叫被终止（当绑定关系查询不到，会推送该事件）
     * 8：Call Forbidden：呼叫被禁止，比如被叫位于黑名单中
     * 9：Buy：被叫忙
     */
    private Integer releaseReason;

    /**
     * 呼叫开始的时间
     */
    private Date startTime;

    /**
     * 呼叫结束的时间
     */
    private Date endTime;

    /**
     * 是否接通
     */
    private Boolean isConnect;

    public LgVoice(String calling, String called, Integer hostingVoiceId, String duration, Date startTime, Date endTime, Boolean isConnect) {
        this.calling = calling;
        this.called = called;
        this.hostingVoiceId = hostingVoiceId;
        this.duration = duration;
        this.startTime = startTime;
        this.endTime = endTime;
        this.isConnect = isConnect;
    }

    public void convertReleaseReason(String releaseReason) {
        if (!CheckUtil.isEmpty(releaseReason)) {
            switch (releaseReason) {
                case "Caller Hang up":
                    this.releaseReason = 1;
                    break;
                case "Called Hang up":
                    this.releaseReason = 2;
                    break;
                case "Not Reachable":
                    this.releaseReason = 3;
                    break;
                case "Route Failure":
                    this.releaseReason = 4;
                    break;
                case "No Answer":
                    this.releaseReason = 5;
                    break;
                case "Abandon":
                    this.releaseReason = 6;
                    break;
                case "Call Terminated":
                    this.releaseReason = 7;
                    break;
                case "Call Forbidden":
                    this.releaseReason = 8;
                    break;
                case "Buy":
                    this.releaseReason = 9;
                    break;
            }
        }
    }
}
